package com.app.business.web.business;

import com.app.business.model.AzProject;
import com.app.business.model.ReduceRecords;
import com.app.business.service.AzProjectService;
import com.app.business.service.ReduceRecordsService;
import com.app.system.jpa.JpaBaseDao;
import com.app.system.permission.model.DataDict;
import com.app.system.permission.service.DataDictService;
import com.app.system.utils.ParamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 物业减免明细统计
 * Created by szy on 2024/7/8
 */
@Controller
@RequestMapping("/business/reduceRecords/*")
@SuppressWarnings("all")
public class ReduceRecordsController extends JpaBaseDao<ReduceRecords,Integer> {
    @Autowired
    private AzProjectService azProjectService;
    @Autowired
    private ReduceRecordsService reduceRecordsService;
    @Autowired
    private DataDictService dataDictService;
    /**
     * 物业减免统计
     * @param modelMap
     */
    @RequestMapping("jmTj")
    public void jmTj(ModelMap modelMap) {
        int yearNow = 2023;
        Map<String, DataDict> townMap = dataDictService.getMapByParentNameForValue("乡镇");
        List<AzProject> azProjectList = this.azProjectService.azProjectList();
        Map<String,Map> jmMap = this.reduceRecordsService.getJmMap(yearNow);
        modelMap.addAttribute("townMap",townMap);
        modelMap.addAttribute("azProjectList", azProjectList);
        modelMap.addAttribute("jmMap", jmMap);
        modelMap.addAttribute("yearNow",yearNow);
    }

    /**
     * 物业减免明细统计
     * @param modelMap
     */
    @RequestMapping("jmTjMx")
    public void jmTjMx(HttpServletRequest request, ModelMap modelMap) {
        String azProjectId = ParamUtils.getString(request, "azProjectId", "");
        String yearNow = ParamUtils.getString(request, "yearNow", "");
        String month = ParamUtils.getString(request, "month", "");
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");
        Map<String, String> propertyTypeMap = this.dataDictService.getMapByParentNameForValue_Name("物业减免类型");
        AzProject azProject = this.azProjectService.findOne(Integer.valueOf(azProjectId));
        //安置信息
        List<Map> getJmMxList = this.reduceRecordsService.getJmMxList(azProjectId,yearNow,month);
        //减免信息
        Map<String,List<Map>> peopleJmMxMap = this.reduceRecordsService.getPeopleJm(azProjectId,yearNow,month);

        modelMap.addAttribute("azProject",azProject);
        modelMap.addAttribute("yearNow",yearNow);
        modelMap.addAttribute("month",month);
        modelMap.addAttribute("houseHoldMap",houseHoldMap);
        modelMap.addAttribute("propertyTypeMap",propertyTypeMap);
        modelMap.addAttribute("getJmMxList",getJmMxList);
        modelMap.addAttribute("peopleJmMxMap",peopleJmMxMap);
    }
}
